package com.css.ids.server.ticket;

import java.io.IOException;
import java.util.Date;

import com.css.ids.server.util.ZipByteUtil;
import com.css.util.Base64Util;

public class TicketValidator {
	public static boolean validate(Date curDate,String code){
		String key = null;
		try {
			key = decode(code);
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
		Ticket ticket = new Ticket(key);
		if(!ticket.isValid())return false;
		System.out.println(ticket.getRemark()+":"+ticket.getTimeStr());
		return curDate.before(new Date(ticket.getTime()));
	}
	public static boolean validate(String code){
		Date curDate = new Date();
		return validate(curDate,code);
	}
	
	private static String decode (String code) throws IOException{
		byte[] key = Base64Util.base64Decode(code);
		return new String(ZipByteUtil.unzip(key));
	}
}
